package com.zzusedating.androidapp;

import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.MenuItem;

import com.zzusedating.androidapp.adapters.FragAdapterMain;
import com.zzusedating.androidapp.tools.MyApplication;

public class MainActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_layout);

        final ViewPager viewPager = findViewById(R.id.Main_ViewPager);
        viewPager.setAdapter(new FragAdapterMain(getSupportFragmentManager()));
        final BottomNavigationView bottomNavView = findViewById(R.id.Main_BottomNavView);

        bottomNavView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.BottomNav_Recommend:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.BottomNav_BBS:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.BottomNav_Discover:
                        viewPager.setCurrentItem(2);
                        break;
                    case R.id.BottomNav_Me:
                        viewPager.setCurrentItem(3);
                        break;
                }
                return false;
            }
        });
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
            @Override
            public void onPageSelected(int position) {
                bottomNavView.getMenu().getItem(position).setChecked(true);
            }
            @Override
            public void onPageScrollStateChanged(int state) {}
        });
    }

}
